package com.ct.controller;

import cn.hutool.log.StaticLog;
import com.ct.R.Result.Result;
import com.ct.anno.LoginCheck;
import com.ct.controller.BaseController.BaseController;
import com.ct.model.ValidVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;

/**
 * 服务端校验
 */
@RestController
public class ValidController extends BaseController {

    /**
     * RequestBody校验
     *
     * @param validVO
     * @return
     */
    @PostMapping("/valid/test1")
    @LoginCheck
    public Result test1(@Validated @RequestBody ValidVO validVO) {
        StaticLog.info("validEntity is {}", validVO);
        return Result.success(validVO);
    }

    /**
     * Form校验
     *
     * @param validVO
     * @return
     */
    @PostMapping(value = "/valid/test2")
    public Result test2(@Validated ValidVO validVO) {
        StaticLog.info("validEntity is {}", validVO);
        return Result.success(validVO);
    }

    /**
     * 单参数校验
     *
     * @return
     */
    @PostMapping(value = "/valid/test3")
    @Validated
    public Result test3( @Max(value = 100, message = "传入数字不能大于100") Integer num) {
        StaticLog.info("email is {}", num);
        return Result.success(num);
    }
}